<?php

namespace modules\levmodules\helpers;


use Lev;
use lev\base\Modulesv;
use lev\helpers\cacheFileHelpers;
use lev\helpers\dbHelper;
use lev\helpers\ModulesHelper;
use modules\levs\modules\ftp\helpers\ftpZipHelper;
use ZipArchive;

!defined('INLEV') && exit('Access Denied LEV');


class zipHelper {

    public static $zipDir = '', $noZipFiles = [], $isAddLev = false, $zipDir2 = '';
    public static $childMud = [];
    public static $unFiles = [];//不压缩指定文件或目录

    public static $devZip = false;//是否压缩测试包

    public static $thisMudFiles = [];//该版本上次压缩文件记录
    public static $preMudFiles = [];//最近一个版本模块文件信息
    public static $mudFiles = [];//存储模块文件 最后修改时间、文件大小、文件路径
    public static $changeFiles = [//存储模块文件对比上个文件 最后修改时间或大小发生变化
        'lastEditTime' => 0,//文件最后改动时间
        'versiontime'  => 0,//最新时间版本号
        'totalSize'    => 0,//文件总大小
        'updateDesc'   => '',//更新描述
        'LevVersion'   => '',//更新时检查Lev基础版本是否支持 默认支持最低，不检查
    ];
    public static $totalSize = 0;//压缩包实际大小

    public static $newZipTime = 0;//新ZIP修改时间（与上一次压缩不同）

    public static function getMudVersionDir($iden, $version, $classdir = false, $README = false) {
        $verDir = $README ? '/README/' : '/versions/'.$version.'/';
        return Lev::getAlias('@modules/../2021-lev-plugin/'.Modulesv::getIdenDir($iden, $classdir).$verDir);
    }

    public static function zipToDir($iden, $classdir = false, $README = false) {
        $mudInfo = Modulesv::getModuleFileInfo($iden);
        $dir = static::getMudVersionDir($iden, $mudInfo['version'], $classdir, $README);
        //Lev::getAlias('@modules/2021-lev-plugin/'.Modulesv::getIdenDir($iden, $classdir).'/versions/'.$mudInfo['version'].'/');
        cacheFileHelpers::mkdirv($dir);
        return $dir;
    }

    public static function versions($iden) {
        $vs = [];
        $zips = glob(dirname(zipHelper::zipToDir($iden)).'/*/');
        if ($zips) {
            foreach ($zips as $v) {
                $name = basename($v);
                $vs[$name] = $name;
            }
        }
        return $vs;
    }

    public static function setPreMudFiles($iden, $version) {
        $vers = static::versions($iden);
        if ($vers) {
            krsort($vers);
            foreach ($vers as $v) {
                if (!static::$thisMudFiles) {// && $v == $version
                    if (is_file($vmudFiles = static::getMudVersionDir($iden, $v).'mudFiles.php')) {
                        static::$thisMudFiles = include $vmudFiles;
                    }
                }else if (!static::$preMudFiles && $v < $version) {
                    if (is_file($vmudFiles = static::getMudVersionDir($iden, $v).'mudFiles.php')) {
                        static::$preMudFiles = include $vmudFiles;
                        break;
                    }
                }
                //if (static::$thisMudFiles && static::$preMudFiles) break;
            }
        }
    }
    public static function setMudFilesAndChangeFiles($fileroot, $_zipFile) {
        if (!is_file($fileroot)) return;
        static::$mudFiles[$_zipFile] = [filemtime($fileroot), filesize($fileroot)];
        static::$totalSize += static::$mudFiles[$_zipFile][1];
        if (static::$preMudFiles || static::$thisMudFiles) {
            if (!isset(static::$thisMudFiles[$_zipFile]) || static::$thisMudFiles[$_zipFile][1] != static::$mudFiles[$_zipFile][1]) {
                //同版本是否有新的改动
                //大小不一样时标注格式时间
                static::$mudFiles[$_zipFile][2] = date('Y-m-d H:i:s', static::$mudFiles[$_zipFile][0]);
                static::$newZipTime = static::$mudFiles[$_zipFile][0];
                static::$changeFiles['versiontime'] = static::$newZipTime;

                (empty(static::$changeFiles['lastEditTime']) || static::$changeFiles['lastEditTime'] < static::$mudFiles[$_zipFile][0]) &&
                static::$changeFiles['lastEditTime'] = static::$mudFiles[$_zipFile][0];

                static::$changeFiles[$_zipFile] = static::$mudFiles[$_zipFile];

            }else if (
                !isset(static::$preMudFiles[$_zipFile]) ||
                static::$preMudFiles[$_zipFile][0] != static::$mudFiles[$_zipFile][0] ||
                static::$preMudFiles[$_zipFile][1] != static::$mudFiles[$_zipFile][1]
            ) {//较上一个版本的改动文件
                static::$changeFiles[$_zipFile] = static::$mudFiles[$_zipFile];
            }
        }
    }

    public static function writeMudFilesAndChangeFiles($iden) {
        $versionDir = static::zipToDir($iden);
        $data = '<?php '.static::getCheckINLEVphpcode().'return '.var_export(static::$mudFiles, true).';';
        $size = file_put_contents($versionDir . 'mudFiles.php', $data);
        if ($size) {
            static::$changeFiles['totalSize'] = static::$totalSize;
            $data = '<?php '.static::getCheckINLEVphpcode().'return '.var_export(static::$changeFiles, true).';';
            file_put_contents($versionDir . 'changeFiles.php', $data);
        }

        //设置文件更新缓存提醒 - 上传至服务器后取消
        if (static::$newZipTime) {
            static::optNewZipCache($iden, static::$changeFiles);
            ModulesHelper::update(['versiontime'=>static::$newZipTime], ['identifier'=>$iden]);
        }
    }
    public static function optNewZipCache($iden, $value = null, $timeout = 0, $clear = null) {
        $ckey = 'new-zip/'.$iden.'/1';
        return cacheFileHelpers::optc($ckey, $value, $timeout, $clear);
    }
    public static function clearCache($iden) {
        $value = static::optNewZipCache($iden);
        static::optNewZipCache($iden, null, 0, true);
        return $value;
    }

    public static function getMudFilesAndChangeFiles($iden) {
        $versionDir = static::zipToDir($iden);
        $arr = [
            'mudFiles' => [], 'changeFiles' => [],
        ];
        if (is_file($file = $versionDir . '/mudFiles.php')) {
            $arr['mudFiles'] = include $file;
        }
        if (is_file($file = $versionDir . '/changeFiles.php')) {
            $arr['changeFiles'] = include $file;
        }
        return $arr;
    }
    public static function getCheckINLEVphpcode() {
        return cacheFileHelpers::getCheckINLEVphpcode();
    }

    public static function zipUnFiles($iden, $unFiles = false) {
        $pfile = dirname($dir = static::zipToDir($iden)).'/un_files.txt';
        $file = $dir.'un_files.txt';
        $unFiles !== false &&
        file_put_contents($file, $json = json_encode($unFiles)) &&
        file_put_contents($pfile, $json);
        return is_file($file) ? json_decode(file_get_contents($file), true) :
            (is_file($pfile) ? json_decode(file_get_contents($pfile), true) : []);
    }

    /**
     * 通过模块标识符（文件夹名称）设置压缩全路径
     * @param $iden
     * @param bool $classdir
     * @param array $replaces
     * @return string
     */
    public static function zipDir($iden, $classdir = false, $replaces = []) {
        $idenDir = Modulesv::getIdenDir($iden, $classdir);
        static::$zipDir = Lev::getAlias('@modules/' . $idenDir . '/');
        static::$zipDir2 = static::$zipDir;
        if ($replaces) {
            if (empty($replaces['add INLEV'])) {
                $addDz = true;
                static::$noZipFiles['unFiles'][] = 'add IN_DISCUZ';
            }else {
                $addDz = 'INLEV';
                static::$noZipFiles['unFiles'][] = $replaces['add INLEV'];
            }
            unset($replaces['add INLEV']);
            $msg = replaceFileContentHelper::createReplaceFiles(static::$zipDir, $replaces, $iden, false, $addDz);
            static::$zipDir = $msg['replacePath'];
            static::$noZipFiles['unAddDz'] = $msg['unAddDz'];
        }
        return static::$zipDir;
    }

    //不压缩指定文件、目录
    public static $exclude = [
        '_lev_dev.bin'    => 1,
        '__table'         => 1,
        'vendor'          => 1,
        'runtime'         => 1,
        'README.md'       => 1,
        'README'          => 1,
        '_lev.config.php' => 1,
        '_lev_demo'       => 1,
        //'open-award-live' => 1,//自动生成的文件夹或文件
    ];

    public static function setDevZip() {
        static::$devZip = true;
        unset(static::$exclude['_lev_dev.bin']);
        static::$exclude['.force.del.bin'] = 1;
    }

    public static function checkExclude($file, $path, $classdir) {
        if (strpos($path, '/_generates/') !== false) {//_generates目录下所有文件全部被压缩
            return false;
        }
        if (isset(static::$unFiles[$path.$file]) || isset(static::$unFiles[static::$zipDir2.$file])) {
//            if ($file == 'modules' && basename($path) == basename(static::$zipDir2)) {
//                static::$noZipFiles['unFiles'][] = $path . $file;
//                return true;
//            }
            static::$noZipFiles['unFiles'][] = $path . $file;
            return true;
        }
        //不压缩指定文件、目录
        $exclude = static::$exclude;
        $basename = basename($file);
        //不压缩web/data目录 .map .bak 后缀文件
        if (
            isset($exclude[$basename]) ||
            ($ext = substr($file, -4)) === '.map' || $ext === '.bak' || $ext === '.zip' || $ext === '.txt' || $ext === '.rar'
            //|| trim(substr($path.$file, -8),'/') === 'web/data'
            //|| trim(substr($classdir.$file, -8),'/') === 'web/data'
        ) {
            static::$noZipFiles['unFiles'][] = $path.$file;
            return true;
        }

        //不压缩组件路由文件 - eg: sign.inc.php
        if (static::$childMud && $path == static::$zipDir && substr($file, -8) == '.inc.php') {
            if (isset(static::$childMud[substr($file, 0, -8)])) {
                static::$noZipFiles['unFiles'][] = $path.$file;
                return true;
            }
        }
        if (substr($file, 0, 1) == "." && $file != '.htaccess') {
            static::$noZipFiles['unFiles'][] = $path . $file;
            return true;
        }
        return false;
    }

    public static function getMudREADME_zip($iden, $classdir) {
        return static::zipToDir($iden, $classdir, true).'README.md.zip';
    }

    public static function addDevFile($zip, $iden) {
        if (static::$devZip) {
            $_idenDir = ModulesHelper::getIdenDir($iden);
            is_file($File = __DIR__ . '/../_generates/_lev_dev.bin') &&
            static::addFile($zip, $File, $_idenDir . '/migrations/data/_lev_dev.bin');
        }
    }

    /**
     * 合并压缩，将两个或以上模块压缩到主模块一起，实现一键安装
     * 子模块除外
     * @param $iden
     * @param array $mergeIdens
     * @param bool $checkHideT 关闭levs主模块前台功能
     * @return array
     */
    public static function doZipMerges($iden, array $mergeIdens, $checkHideT = false, $unzip = true, array $changeAdminEnter = []) {
        $mudInfo = Modulesv::getModuleFileInfo($iden);
        $dir = static::getMudVersionDir($iden, $mudInfo['version']);
        $zipFile = $dir . $iden . '.zip';
        $dir .= 'merges/_temp/';//临时解压缩目录
        if ($unzip) {
            $renameDir = rtrim($dir, '/').'_/';
            //cacheFileHelpers::rmdirv($renameDir, true);//清空临时目录 无效 需要手动
            cacheFileHelpers::mkdirv($renameDir);
            is_dir($dir) && rename($dir, $renameDir.'_'.microtime(true));
            cacheFileHelpers::mkdirv($dir);
        }
        $cutnum = strlen($dir);
        $newZip = dirname($dir) . '/' . $iden . '.zip';
        copy($zipFile, $newZip);
        $zip = new ZipArchive();
        if (!$zip->open($newZip)) {
            return Lev::responseMsg(-10011, '压缩包打开失败：'.$newZip);
        }
        foreach ($mergeIdens as $classdir => $idens) {
            foreach ($idens as $_mudInfo) {
                //$_mudInfo = Modulesv::getModuleFileInfo($_iden);
                $_iden = $_mudInfo['identifier'];
                $_dir = static::getMudVersionDir($_iden, $_mudInfo['version']);
                $zipname = $classdir ?: $_iden;
                if ($unzip) {
                    $_zip = new ZipArchive();
                    if ($_zip->open($_dir . $zipname . '.zip')) {
                        $_zip->extractTo($dir);
                        $_zip->close();
                    }
                    continue;
                }
                $mIdens[] = $_iden;
                $merges[$_iden] = [
                    'identifier'    => $_mudInfo['identifier'],
                    'classdir'      => $_mudInfo['classdir'],
                    'name'          => $_mudInfo['name'],
                    'descs'         => $_mudInfo['descs'],
                    'versiontime'   => $_mudInfo['versiontime'],
                    'version'       => $_mudInfo['version'],
                ];
                if (!$classdir) {
                    $unFilesArr = [];
                    if (!isset($xmldata) && $iden != 'levs' && $_iden == 'levs') {
                        $path = $dir . $_iden . '/';
                        is_file($xmlFile = $path . 'discuz_plugin_levs.xml') && @unlink($xmlFile);
                        is_file($xmlFile = $path . 'discuz_plugin_levs_SC_UTF8.xml') && @unlink($xmlFile);
                        is_file($xmlFile = $path . 'discuz_plugin_levs_SC_GBK.xml') && @unlink($xmlFile);

                        $xmldata = '';
                    }
                    static::addFileToZip($dir . $_iden . '/', $zip, $_iden, '', $cutnum, '', $unFilesArr);
                    static::addDevFile($zip, $_iden);
                }

            }
            if (!$unzip && $classdir) {
                static::addFileToZip($dir . $classdir . '/', $zip, $classdir, '', $cutnum);
                static::addDevFile($zip, $classdir);
            }
        }
        if ($checkHideT && is_file($setFile = $dir . 'levs/migrations/data/settings.php')) {
            $settings = include $setFile;
            foreach ($settings as $k => $v) {
                if ($v['inputname'] == 'SiteName') {
                    $v['inputvalue'] = '-';
                    $settings[$k] = $v;
                    break;
                }
            }
            $settings = '<?php ' . static::getCheckINLEVphpcode() . 'return ' . var_export($settings, true) . ';';
            file_put_contents($setFile, $settings);
        }
        if ($changeAdminEnter && is_file($adminFile = $dir . '/levs/web/admin.php')) {
            $data = file_get_contents($adminFile);
            $replace = '';
            foreach ($changeAdminEnter as $keyv => $rkv) {
                ($rkv || is_numeric($rkv)) &&
                $replace.= '$_GET[\''.$keyv.'\'] = "'.$rkv.'";';
            }

            $data = str_replace('/*** 此行为替换行，不可改动 ***/', $replace, $data);
            file_put_contents($adminFile, $data);
        }
        if ($unzip) {
            //刚解压出来包不能删除和修改文件，需要二次请求。首次请求解压，
            return Lev::responseMsg(2, '压缩包解压完成，等待再次请求合并');
        }else {
            $tip = implode('-', $mIdens);
            if (!empty($merges)) {
                //$merges[] = $iden;
                $dataIdens = '<?php ' . static::getCheckINLEVphpcode() . 'return ' . var_export($merges, true) . ';';
                file_put_contents($dir . 'levs/migrations/data/merge_install.php', $dataIdens);
                file_put_contents(dirname($newZip) . '/insInfo.txt', date('Y-m-d H:i:s') . "\r\n" . var_export($merges, true));
            }
        }
        $zip->close();
        return Lev::responseMsg(1, '合并压缩完成：'.$tip);
    }

    /**
     * 压缩模块展示内容
     * @param $iden
     * @param $classdir
     * @return array
     */
    public static function doZipREADME_md($iden, $classdir) {
        $idenDir = Modulesv::getIdenDir($iden, $classdir);
        static::$zipDir = Lev::getAlias('@modules/' . $idenDir . '/README.md/');
        if (!is_dir(static::$zipDir)) {
            static::$zipDir = Lev::getAlias('@modules/' . $idenDir . '/README/');
            if (!is_dir(static::$zipDir)) {
                return Lev::responseMsg(-1, '模块未设置，展示内容目录：' . static::$zipDir);
            }
        }

        $zippath = static::getMudREADME_zip($iden, $classdir);

        $zip = new ZipArchive();
        if($zip->open($zippath, is_file($zippath) ? ZipArchive::OVERWRITE : ZipArchive::CREATE)=== TRUE){
            unset(static::$exclude['README.md']);

            static::addFileToZip(static::$zipDir, $zip, $iden, '', false, 'README.md');
            $zip->close(); //关闭处理的zip文件
        }
        return Lev::responseMsg(1, '成功压缩');
    }

    public static function createDzXml($iden, $path, $mudInfo) {
        if (is_file($filename = $path.'discuz_plugin_'.$iden.'.xml')) {
            $version = $mudInfo['version'];
            $data = file_get_contents($filename);
            $data = str_replace('Levme.com', 'L', $data);
            $data = str_replace('Lev', '', $data);
            strpos($data, '<![CDATA[X3.4]]>') !== false &&
            ($data = str_replace('<![CDATA[X3.4]]>', '<![CDATA[X3,X3.1,X3.2,X3.3,X3.4]]>', $data));

            strpos($data, $version) === false && ($srh = strstr(strstr($data, 'id="version">'), '</item>', true)) &&
            ($data = str_replace($srh, 'id="version"><![CDATA['.$version.']]>', $data));
            file_put_contents($filename, $data);
            file_put_contents($path.'discuz_plugin_'.$iden.'_SC_UTF8.xml', $data);


            file_put_contents(static::$zipDir2.'discuz_plugin_'.$iden.'.xml', $data);
            file_put_contents(static::$zipDir2.'discuz_plugin_'.$iden.'_SC_UTF8.xml', $data);

            $gbkdata = file_get_contents($filename);
            //$gbkdata = str_replace('encoding="ISO-8859-1"', 'encoding="gbk"', $gbkdata);
            $gbkdata = str_replace('Levme.com', 'L', $gbkdata);
            $gbkdata = str_replace('Lev', '', $gbkdata);
            $data = Lev::iconvs($gbkdata, 'UTF-8', 'GBK');
            file_put_contents($path.'discuz_plugin_'.$iden.'_SC_GBK.xml', $data);

            file_put_contents(static::$zipDir2.'discuz_plugin_'.$iden.'_SC_GBK.xml', $data);
        }
    }

    /**
     * @param $iden
     * @param bool $classdir
     * @param bool $addLev 是否加入Lev基础包使本插件能独立运行
     * @param array $unFiles 不压缩指定文件或目录
     * @param array $replaces
     * @param string $updateDesc
     * @return array
     */
    public static function doZip ($iden, $classdir = false, $addLev = false, $unFiles = [], $replaces = [], $updateDesc = '')
    {
        $zip = new ZipArchive();
        $mudInfo = Modulesv::getModuleFileInfo($iden);
        $classdir === false && $classdir = $mudInfo['classdir'];
        !$classdir && static::$childMud = ModulesHelper::findAllField('identifier', ['classdir'=>$iden], 'identifier');

        static::setPreMudFiles($iden, $mudInfo['version']);

        static::$isAddLev = (APPVIDEN != $iden && !$classdir && $addLev);
        static::$unFiles = $unFiles;

        $zippath = static::zipToDir($iden, $classdir).($classdir?:$iden).'.zip';
        $tips = Lev::responseMsg(1, '成功压缩为 前置版');
        if($zip->open($zippath, is_file($zippath) ? ZipArchive::OVERWRITE : ZipArchive::CREATE)=== TRUE){
            $path = static::zipDir($iden, $classdir, $replaces);
            if(is_dir($path)){  //给出文件夹，打包文件夹
                static::createDzXml($iden, $path, $mudInfo);
                $version = Lev::actionObjectMethod('modules\\'.Modulesv::getIdenNs($iden).'\\' . $iden . 'Helper', [], 'getModuleVersion');
                static::addFileToZip($path, $zip, $iden, $classdir ? $classdir.'/modules/' : '', false, '', [], $version);
            }else if(is_array($path)){  //以数组形式给出文件路径
                foreach($path as $file){
                    $zip->addFile($file);
                }
            }else if (is_file($path)){      //只给出一个文件
                $zip->addFile($path);
            }else {
                $tips = Lev::responseMsg(-1, '文件夹不存在！');
            }

            if ($tips['status'] >0) {
                static::addForceDelFile($zip, $iden);

                if (static::$isAddLev) {
                    $path = static::zipDir(APPVIDEN, '');

                    $cutnum = strlen($path);
                    static::addFileToZip($path . 'lev/', $zip, $iden, $iden . '/lev/', $cutnum + strlen('lev/'));
                    static::addFileToZip($path . 'web/', $zip, $iden, $iden . '/web/', $cutnum + strlen('web/'));
                    $zip->addFile($path . '/iden.const.php', $iden . '/iden.const.php');
                    $tips = Lev::responseMsg(1, '成功压缩为 <font color=red>独立版</font>');

                }
                APPVIDEN == $iden && $tips = Lev::responseMsg(1, 'Lev主程序自动压缩为 <font color=red>独立版</font>');

                static::$changeFiles['updateDesc'] = $updateDesc;
                static::zipUnFiles($iden, static::$unFiles);
                static::writeMudFilesAndChangeFiles($iden);

            }

            //$zip->setPassword('123123');
            $zip->close(); //关闭处理的zip文件

            $tips['READEME.md'] = static::doZipREADME_md($iden, $classdir);
        }else {
            $tips = Lev::responseMsg(-1, '创建失败！');
        }
        $tips['文件大小'] = [
            '压缩前' => round(static::$totalSize/1024/1024, 2).'MB',
            '压缩后' => round(filesize($zippath)/1024/1024, 2).'MB',
        ];
        $tips['未压缩文件'] = static::$noZipFiles;
        $tips['有变动的文件'] = static::$changeFiles;
        return $tips;
    }

    private static function addFileToZip($path, $zip, $zipname, $classdir = '', $cutnum = false, $unZipDirname = '', $unFiles = [], $version = '')
    {
        $path = rtrim($path, '/') . '/';
        $cutnum === false && $cutnum = strlen(rtrim(dirname(static::$zipDir), '/')) + 1;
        $_zipFilePath = substr($path, $cutnum);
        $_zipFilePath = static::getZipFilePath($_zipFilePath, $unZipDirname);
        $zipFilePath = rtrim($classdir . $_zipFilePath, '/');
        if (!is_dir($path)) return;
        $handler = opendir($path);
        while (($filename = readdir($handler)) !== false) {
            //文件夹文件名字为'.'和‘..’，不要对他们进行操作
            if ($filename != "." && $filename != ".." && !static::checkExclude($filename, $path, $classdir)) {
                $_src = $path . $filename;
                if (!isset($unFiles[$_src])) {
                    if (is_dir($_src)) {// 如果读取的某个对象是文件夹，则递归
                        if (1 || substr($filename, 0, 1) != ".") {
                            $zip->addEmptyDir($zipFilePath . '/' . $filename);
                            static::addFileToZip($_src, $zip, $zipname, $classdir, $cutnum, $unZipDirname, $unFiles, $version);
                        }
//                        else {
//                            static::$noZipFiles[] = $filename;
//                        }
                    } else if (1 || substr($filename, 0, 1) != "." || $filename == '.htaccess') { //将文件加入zip对象
                        if (static::$isAddLev && $filename == 'iden.const.php') {
                        } else {
                            static::addFile($zip, $_src, $_zipFile = $zipFilePath . '/' . $filename, $version);
                        }
                    }
//                    else {
//                        static::$noZipFiles[] = $filename;
//                    }
                }
//                else {
//                    static::$noZipFiles['unFiles'][] = $_src;
//                }
            }
        }
        @closedir($path);
    }

    public static function setVersionVar($src, $version) {
        if ($version && substr($src, -3) === '.js') {
            $data = file_get_contents($src);
            if (strpos($data, '#v#}}') !== false) {
                $arr = explode('#v#}}', $data);
                foreach ($arr as $v) {
                    ($str = strstr($v, '{{#v#')) &&
                    $data = str_replace($str . '#v#}}', '{{#v#' . $version . '#v#}}', $data);
                }
                file_put_contents($src, $data);
            }
        }
    }

    private static function getZipFilePath($_zipFilePath, $unZipDirname) {
        if ($unZipDirname) {
            $arr = explode("/", $_zipFilePath);
            $arr[0] = $unZipDirname;
            $_zipFilePath = implode("/", $arr);
        }
        return $_zipFilePath;
    }

    private static function addFile($zip, $pathFilename, $_zipFile, $version = '') {
        static::setVersionVar($pathFilename, $version);
        $zip->addFile($pathFilename, $_zipFile);
        static::setMudFilesAndChangeFiles($pathFilename, $_zipFile);
    }

    private static function addForceDelFile($zip, $iden)
    {
        if (static::$devZip) {
            is_file($File = __DIR__ . '/../_generates/_lev_dev.bin') &&
            static::addFile($zip, $File, ModulesHelper::getIdenDir($iden) . '/migrations/data/_lev_dev.bin');
        }else {
            $ck = !is_file($forceFile = __DIR__ . '/../_generates/.force.del.bin') ?
            file_put_contents($forceFile, 1) : 2;
            $ck &&
            static::addFile($zip, $forceFile, ModulesHelper::getIdenDir($iden) . '/migrations/data/.force.del.bin');
        }
    }
}







